package com.ruoyi.business.service.impl;

import com.ruoyi.framework.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.ruoyi.business.domain.BusAttachment;
import com.ruoyi.business.mapper.BusAttachmentMapper;
import com.ruoyi.business.service.BusAttachmentService;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
*内容: 
*作者: cy
*/   
    
   
@Service
public class BusAttachmentServiceImpl implements BusAttachmentService{

    @Resource
    private BusAttachmentMapper busAttachmentMapper;
    @Autowired
    private ServerConfig serverConfig;

    @Override
    public int deleteByPrimaryKey(Integer fileId) {
        return busAttachmentMapper.deleteByPrimaryKey(fileId);
    }

    @Override
    public int insert(BusAttachment record) {
        return busAttachmentMapper.insert(record);
    }

    @Override
    public int insertSelective(BusAttachment record) {
        return busAttachmentMapper.insertSelective(record);
    }

    @Override
    public BusAttachment selectByPrimaryKey(Integer fileId) {
        return busAttachmentMapper.selectByPrimaryKey(fileId);
    }

    @Override
    public int updateByPrimaryKeySelective(BusAttachment record) {
        return busAttachmentMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(BusAttachment record) {
        return busAttachmentMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<String> selectCarImgs(String carNumber) {
        List<String> carImgs = busAttachmentMapper.selectImgListByCarNumber(carNumber);
        if (CollectionUtils.isEmpty(carImgs)){
            throw new IllegalArgumentException("该车辆暂无图片");

        }
        //这个路径是没有项目的ip和端口的
        //这里我们去获取当前项目的ip和端口
        String url = serverConfig.getUrl();
        return carImgs.stream()
                .map(imgs -> url + imgs)
                .collect(Collectors.toList());

    }

}
